/**
 * 
 */
package com.geezdata.cps.ttk.domain.factory;

import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.geezdata.cps.base.utils.BeanUtil;
import com.geezdata.cps.ttk.common.request.CreateOrUpdateGoodsRequest;
import com.geezdata.cps.ttk.common.vo.GoodsReqVO;
import com.geezdata.cps.ttk.domain.domain.Goods;

/**
 * @author tfwan
 * @date 创建时间：2018年6月12日 下午4:03:18
 *
 */
public class GoodsFactory {

	public static Goods newInstance(CreateOrUpdateGoodsRequest request , Goods exsitsGoods) {
		GoodsReqVO goodsReqVO = request.getGoodsReqVO();
		Goods goods = BeanUtil.convert(goodsReqVO, Goods.class);
		goods.setGoodJson(JSONObject.toJSONString(goods));
    	Date now = new Date();
    	String currentUser = request.getCurrentUser();
    	
    	if (exsitsGoods == null) {
    		goods.setCreatedUser(currentUser);
    		goods.setCreatedAt(now);
    		goods.setStatus(1);
    	} else {
    		goods.setGoodsId(exsitsGoods.getGoodsId());
    	}
    	
    	goods.setUpdatedUser(currentUser);
    	goods.setUpdatedAt(now);
        return goods;
	}
}
